package com.bangcommunity.bbframe.fdfs;

import java.io.Serializable;

/**
 * @author tanghc
 * @date 18/6/22
 */
public class StorageAddress implements Serializable {
    private static final long serialVersionUID = -7750979324074447430L;
    private String host;
    private int port;
    private int storePathIndex = 0;

    public StorageAddress(String host, int port, int storePathIndex) {
        this.host = host;
        this.port = port;
        if (storePathIndex < 0) {
            this.storePathIndex = 256 + storePathIndex;
        } else {
            this.storePathIndex = storePathIndex;
        }
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getStorePathIndex() {
        return storePathIndex;
    }

    public void setStorePathIndex(int storePathIndex) {
        this.storePathIndex = storePathIndex;
    }
    public String toStorageAddressKey(){
        return this.host+":"+this.port;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        StorageAddress that = (StorageAddress) o;

        if (port != that.port) return false;
        return !(host != null ? !host.equals(that.host) : that.host != null);

    }

    @Override
    public int hashCode() {
        int result = host != null ? host.hashCode() : 0;
        result = 31 * result + port;
        return result;
    }
}
